<template>
  <div style="width: 100%">
        <a-card class="card" :bordered="false" >
    <div class="table-page-search-wrapper">
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :sm="{span:24}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="招生学年">
              <a-select :allowClear="true" showSearch optionFilterProp="children"  v-model="queryParam.zsxn">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:16}" :xl="{span:8}">
            <a-button type="primary" @click="loadData" style="margin-top:29px">查询</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
  </a-card >  
    <a-card title="院系报名人数统计" :bordered="false">
      <div id="mountNode"></div>
    </a-card>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import G2 from '@antv/g2'
const selectArr = ['TYPE0126']
export default {
  name: 'Signup',
  data () {
    return {
      chart:null,
      queryParam:{
        zsxn:''
      }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  activated(){
     this.chart = new G2.Chart({
        container: 'mountNode',
        forceFit: true,
        height: 700,
        padding: [ 20, 80, 230, 80 ]
      });
    this.loadData()
  },
  deactivated(){
    this.chart.destroy()
  },
  methods: {
    loadData(){
      if(!this.queryParam.zsxn)this.queryParam.zsxn = ''
      this.$api.situation.signup(this.queryParam).then(res => {
        var data = res.data
      this.chart.clear()
      this.chart.source(data);
      this.chart.scale('count', {
        tickInterval: 200
      });
      if(data.length>15){
       this.chart.axis('item', {
          label: {
            textStyle: {
              textAlign:'start',
              fill: '#aaaaaa',
              fontSize: '12',
              rotate:45
            },
            autoRotate:false,
          },
          tickLine: {
            alignWithLabel: false,
            length: 0
          }
      });}else{
          this.chart.axis('item', {
                label: {
                  textStyle: {
                    fill: '#aaaaaa',
                    fontSize: '12',
                  },
                },
                tickLine: {
                  alignWithLabel: false,
                  length: 0
                }
        });
      }
      this.chart.interval().position('item*count');
      this.chart.render();
      })
      
    }
  }
}
</script>
<style lang='less' scoped>
.card{
  margin-bottom: 20px;
}
</style>
